package testcase.doctor;

import common.Host;
import common.TestData;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import api.doctor.UpdateStatus;

/**
 * 帮忙医医生上下线UpdateStatus接口测试用例
 * @author gaowen
 *
 */
public class TestUpdateStatus
{
	/**
	 * 帮忙医医生上下线UpdateStatus接口测试环境数据驱动
	 * @return 测试数据
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws ParserConfigurationException 
	 */
	@DataProvider (name = "Test")
	public static String[][] testUpdateStatusDataProvider() throws ParserConfigurationException, SAXException, IOException
	{
		Host.setup("Test");
		TestData td = new TestData("doctor/TestUpdateStatus.xml");
		return td.getParam();
	}
	
	/**
	 * 帮忙医医生上下线UpdateStatus接口测试环境用例
	 * @param caseName - 用例名称
	 * @param online - 在线状态：true上线，false下线
	 * @param version - 版本
	 * @param doctorID - 医生ID
	 * @param token - 医生token
	 * @throws IOException 
	 * @throws JSONException 
	 */
	@Test (dataProvider = "Test", groups = {"Test"})
	public void testUpdateStatusTestCase(String caseName, String online, String version, String doctorID, String token) throws IOException, JSONException 
	{
		String result = UpdateStatus.put(online, version, doctorID, token);
		
		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}

		//设置检查点
		Boolean checkpoint;
		switch (caseName) {
		case "Online":
			checkpoint = jsonResult.getBoolean("Data");
			Assert.assertTrue(checkpoint); // 接口返回Data字段是否为True
			break;
		case "Offline":
			checkpoint = jsonResult.getBoolean("Data");
			Assert.assertFalse(checkpoint); // 接口返回Data字段是否为False
			break;
		case "DoctorIDError":
			Assert.assertNull(jsonResult); // 接口返回数据是否为空
			break;
		case "Onlinenull":
			Assert.assertNull(jsonResult); // 接口返回数据是否为空
			break;
		case "VersionNull":
			Assert.assertNull(jsonResult); // 接口返回数据是否为空
			break;
		case "DoctorIDNull":
			Assert.assertNull(jsonResult); // 接口返回数据是否为空
			break;
		}
	}
}